package com.ruoyi.system.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SysQuestionRecord;
import com.ruoyi.system.service.ISysQuestionRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题回答记录Controller
 * 
 * @author ruoyi
 * @date 2022-05-22
 */
@RestController
@RequestMapping("/system/questionrecord")
public class SysQuestionRecordController extends BaseController
{
    @Autowired
    private ISysQuestionRecordService sysQuestionRecordService;

    /**
     * 查询问题回答记录列表
     */
  //  @PreAuthorize("@ss.hasPermi('system:questionrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysQuestionRecord sysQuestionRecord)
    {
        startPage();
        List<SysQuestionRecord> list = sysQuestionRecordService.selectSysQuestionRecordList(sysQuestionRecord);
        return getDataTable(list);
    }

    /**
     * 导出问题回答记录列表
     */
   // @PreAuthorize("@ss.hasPermi('system:questionrecord:export')")
    @Log(title = "问题回答记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysQuestionRecord sysQuestionRecord)
    {
        List<SysQuestionRecord> list = sysQuestionRecordService.selectSysQuestionRecordList(sysQuestionRecord);
        ExcelUtil<SysQuestionRecord> util = new ExcelUtil<SysQuestionRecord>(SysQuestionRecord.class);
        util.exportExcel(response, list, "问题回答记录数据");
    }

    /**
     * 获取问题回答记录详细信息
     */
   // @PreAuthorize("@ss.hasPermi('system:questionrecord:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId)
    {
        return AjaxResult.success(sysQuestionRecordService.selectSysQuestionRecordByQuestionId(questionId));
    }

    /**
     * 新增问题回答记录
     */
   // @PreAuthorize("@ss.hasPermi('system:questionrecord:add')")
    @Log(title = "问题回答记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysQuestionRecord sysQuestionRecord)
    {
        sysQuestionRecord.setCreateBy(getLoginUser().getUser().getNickName());
        return toAjax(sysQuestionRecordService.insertSysQuestionRecord(sysQuestionRecord));
    }

    /**
     * 修改问题回答记录
     */
    //@PreAuthorize("@ss.hasPermi('system:questionrecord:edit')")
    @Log(title = "问题回答记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysQuestionRecord sysQuestionRecord)
    {
        sysQuestionRecord.setCreateBy(getLoginUser().getUser().getNickName());
        sysQuestionRecord.setUpdateTime(DateUtils.getNowDate());
        return toAjax(sysQuestionRecordService.updateSysQuestionRecord(sysQuestionRecord));
    }

    /**
     * 删除问题回答记录
     */
   // @PreAuthorize("@ss.hasPermi('system:questionrecord:remove')")
    @Log(title = "问题回答记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds)
    {
        return toAjax(sysQuestionRecordService.deleteSysQuestionRecordByQuestionIds(questionIds));
    }
}
